/**
 * 
 */
package cen5501c.common;

import java.util.List;

/**
 * @author Jiangyan Xu
 * 
 */
public class CommandFactory {
	/**
	 * Creates CmdBase instance from operation name
	 * 
	 * @param operation
	 *            Operation name
	 * @throws Exception
	 *             if invalid arguments are present
	 */
	public static CmdBase createCmd(String operation, List<String> args)
			throws Exception {
		CmdBase ret = null;
		// TODO Change to enum impl.

		if (operation.equals(GetFileCmd.OPERATION)) {
			ret = new GetFileCmd(args);
		} else if (operation.equals(FileContentCmd.OPERATION)) {
			ret = new FileContentCmd(args);
		} else if (operation.equals(FileListCmd.OPERATION)) {
			ret = new FileListCmd(args);
		} else if (operation.equals(ListFilesCmd.OPERATION)) {
			ret = new ListFilesCmd(args);
		} else if (operation.equals(GetDelayCmd.OPERATION)) {
			ret = new GetDelayCmd(args);
		} else if (operation.equals(DelayCmd.OPERATION)) {
			ret = new DelayCmd(args);
		} else if (operation.equals(ErrorCmd.OPERATION)) {
			ret = new ErrorCmd(args);
		} else if (operation.equals(LocalErrorCmd.OPERATION)) {
			ret = new LocalErrorCmd(args);
		} else {
			throw new IllegalArgumentException("Command type invalid.");
		}
		return ret;
	}
}
